<?php

namespace plugins\pay\controller;

use plugins\pay\controller\BaseController;

use plugins\pay\lib\Pay;



class AlipayController extends BaseController

{

    public $title = '支付宝';

    public $tag   = 'alipay';    

    

    //配置页面

    public function config( $var )

    {

        $configs = Pay::getConfigs( 'alipay' );

        $this->assign( 'configs' , $configs );

        return $this->display( $var );

    }

    

    //设置配置

    public function setConfig()

    {

        $data = $this->request->param();

        $config = [

            "icon" => '',

            "alipay_getway" => '',

            "appid" => '',

            "app_private_key" => '',

            "alipay_public_key" => '',

        ];

        if( isset( $data [ 'config' ] ) ) $config = $data[ 'config' ];

        $res = Pay::setConfigs( 'alipay' , $config );

        if( !$res ){

            return api_json_echo( false , '保存失败' );

        }

        return api_json_echo( true , '保存成功' );

    }

    /**

     * 回调地址

     */

    public function noticeurl()

    {

        //支付宝回调参数

        $param = $this->request->post();


        $param['fund_bill_list'] = htmlspecialchars_decode($param['fund_bill_list']);



        $alipay = Pay::createInstance(  $this->tag  );   //创建pay的class



        $res   = $alipay->notify( $param );

    }

    

}